#pragma once

#include<iostream>
#include<stdarg.h>
#include<assert.h>
#include<time.h>

#define DEBUG 0
#define NOTICE 1
#define WARNING 2
#define FATAL 3

using namespace std;

const char* log_level[]={"DEBUG","NOTICE","WARNING","FATAL"};

//可变参数列表
void LogMessage(int level,const char*format,...)
{
    assert(level>=DEBUG);
    assert(level<=FATAL);
    char info[1024];
    va_list ap;
    va_start(ap,format);
    vsnprintf(info,sizeof(info)-1,format,ap);
    va_end(ap);
    char* name=getenv("USER");
    FILE* out=(level==FATAL)?stderr:stdout;
    fprintf(out,"%s | %u | %s | %s\n",log_level[level],(unsigned int)time(nullptr),name,info);
}